package nio.base;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class BufferTest {

    public static void main(String[] args) throws IOException {

        RandomAccessFile file = new RandomAccessFile("write.txt", "rw");
        FileChannel channel = file.getChannel();

        ByteBuffer buf = ByteBuffer.allocate(100);
        buf.put("三大法师".getBytes());
        buf.put("sadfasdf".getBytes());
        buf.put("撒打发斯蒂芬".getBytes());

//		buf.rewind(); //切换到读模式
        buf.flip();

        channel.write(buf);
        channel.force(true);

        channel.close();
        file.close();
    }
}
